package easy

import (
	"workspace/node"
)

func SumRootToLeaf(root *node.TreeNode) int {
	return dfs1(root, 0)
}
func dfs1(node *node.TreeNode, val int) int {
	if node == nil {
		return 0
	}
	val = val<<1 | node.Val
	if node.Left == nil && node.Right == nil {
		return val
	}
	return dfs1(node.Left, val) + dfs1(node.Right, val)
}
